﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PMS.Model;
using System.Data.OleDb;
using PMS.DBUtility;

namespace PMS.DAL
{
    public class CustomerDAL
    {
        private readonly string sql = "insert into P_Custom (CustomerName,Tel,Mobile,Email,Contacts,Address,CustomerType,CPinYin) values(?,?,?,?,?,?,?,?)";
        private readonly string sql2 = "select * from P_Custom";
        public bool Insert(Model.Custom custom)
        {
            OleDbParameter[] parameters = new OleDbParameter[8];
            parameters[0] = new OleDbParameter("?", custom.CustomerName);
            parameters[1] = new OleDbParameter("?", custom.Tel);
            parameters[2] = new OleDbParameter("?", custom.Mobile);
            parameters[3] = new OleDbParameter("?", custom.Email);
            parameters[4] = new OleDbParameter("?", custom.Contacts);
            parameters[5] = new OleDbParameter("?", custom.Address);
            parameters[6] = new OleDbParameter("?", custom.CustomerType);
            parameters[7] = new OleDbParameter("?",custom.CPinYin);
            if (SQLHelper.Execute(sql, parameters) > 0)
            {
                return true;
            }
            else
            {
                return false;
            }             

        }
        public bool Update()
        {
            return true;
        }
        public bool Delete(string Id)
        {
            return true;
        }
        public IList<Model.Custom> GetAllList()
        {
            return GetList(sql2);
        }
        public IList<Model.Custom> GetList(string strsql)
        {
            List<Model.Custom> cusList = new List<Custom>();       
            System.Data.DataSet ds = SQLHelper.GetData(strsql);
            System.Data.DataTable table = ds.Tables[0];
            foreach (System.Data.DataRow row in table.Rows)
            {
                Model.Custom cus = new Model.Custom();
                cus.Id = (int)row[0];
                cus.CustomerName = (string)row[2];
                cus.Tel = (string)row[3];
                cus.Mobile = (string)row[4];
                cus.Email = (string)row[5];
                cus.Contacts = (string)row[6];
                cus.Address = (string)row[7];
                cus.CustomerType = (short)row[8];
                cus.CPinYin = (string)row[9];
                cusList.Add(cus);
            }
            return cusList;

        }
    }
}
